<template>
  <el-container>
    <el-main class="main-select-body bgfff">
      <div class="table-bg"></div>
      <el-table
        class="marT20"
        :data="tableData"
        :height="tableHeight"
        v-loading="loading"
        @row-dblclick="dialogEdit"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >
        <el-table-column width="70" align="center" type="index" label="序号"></el-table-column>
        <el-table-column
          v-for="item in columns"
          :key="item.prop"
          :prop="item.prop"
          :label="item.label"
          align="center"
        ></el-table-column>
        <el-table-column :label="$t('base.table.action')" width="300">
          <template slot-scope="scope">
            <el-button type="text" @click="dialogView(scope.row)">进入演习</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="changePageSize"
        @current-change="changePageNo"
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
      ></el-pagination>
    </el-main>
  </el-container>
</template>
<script>
import { drillDetailAPI as request, userAPI } from "@/api";
import curd from "@/mixins/curd";
import { getOrg, getUser } from "@/utils";
export default {
  mixins: [curd],
  data() {
    return {
      request: request,
      columns: [
        { prop: "maneuverName", label: "演习科目" },
        { prop: "maneuverStatusText", label: "状态" },
        { prop: "principalName", label: "演习负责人" },
        { prop: "orgName", label: "所属机构" },
        { prop: "createTime", label: "创建时间" },
      ],
    };
  },
  methods: {
    formatTableData(tableData) {
      tableData.forEach((el) => {
        el.maneuverStatusText = "";
        if (el.maneuverStatus == 0) {
          el.maneuverStatusText = "禁用";
        } else if (el.maneuverStatus == 1) {
          el.maneuverStatusText = "启用";
        }
      });
    },
    dialogView(item) {
      let url = "";
      userAPI.getRoleType({ maneuverId: item.id }).then((res) => {
        let value = res.role;
        // 导调
        if (value == "0") {
          url = this.$router.resolve({
            path: "/drill-daodiao-detail/" + item.id,
          });
          window.open(url.href, "_blank");
          return;
        }

        // 参战
        if (value == "1") {
          url = this.$router.resolve({
            path: "/drill-canzhan-detail/" + item.id,
          });
          window.open(url.href, "_blank");
          return;
        }

        // 观战 大屏
        if (value == "2" || value == "3") {
          url = this.$router.resolve({
            path: "/drill-guanzhan-detail/" + item.id,
          });
          window.open(url.href, "_blank");
          return;
        }
      });
    },
  },
};
</script>
